<template>
  <div class="echarts">
    <header>
      <h2 style="color: #fff;">大数据可视化</h2>
    </header>
    <body class="body">
      <div class="left item" ref="leftbody"></div>
      <div class="main item" ref="mainbody"></div>
      <div class="right item" ref="rightbody"></div>
    </body>
  </div>
</template>


<script setup>
import { ref, onMounted } from 'vue';
import * as echarts from 'echarts';
const leftbody = ref(null);
const mainbody = ref(null);
const rightbody = ref(null);
const chartfn = () => {
  const myChart = echarts.init(leftbody.value);
  const option = {
    title: {
      text: 'ECharts 柱状图',
      textStyle: {
        color: '#000'
      },
      right: 'center'
    },
    tooltip: {},
    xAxis: {
      data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],
      axisTick: {
        show: false
      },
      type: "category",
    },
    yAxis: {
      type: 'category',
    },
    grid: {
      top: "20%",
      left: "3%",
      right: "4%",
      bottom: "3%",
      show: true, //显示边框
      borderColor: "#012f4a", // 边框颜色
      containLabel: true,
    },
    legend: {
    data: ['销量', '金额'],
    textStyle: {
      color: '#000'
    },
    top: '8%'
    },
    series: [
    {
      name: '销量',
      type: 'bar',
      data: [5, 20, 36, 10, 10, 20]
    },
    {
      name: '金额',
      type: 'bar',
      data: [50, 200, 360, 100, 100, 200]
    }
  ]
  };
  myChart.setOption(option);
}

const piefn = () => {
  const pieChart = echarts.init(mainbody.value);
  const pieoption = {
    title: {
      text: 'ECharts 饼图',
      textStyle: {
        color: '#000'
      },
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '8%',
      left: 'center',
      textStyle: {
        color: '#000'
      },
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '90%'],
        data: [
          { value: 1048, name: 'Search Engine' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union Ads' },
          { value: 300, name: 'Video Ads'}],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
      },
      {
        name: 'Access From',
        type: 'pie',
        radius: ['0%', '30%'],
        data: [
          { value: 1048, name: 'Search Engine' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union Ads' },
          { value: 300, name: 'Video Ads'}],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ],
  }
  pieChart.setOption(pieoption)
}
const linefn = () => {
  const lineChart = echarts.init(rightbody.value);
  const lineOption = {
    title: {
      text: 'ECharts 折线图',
      textStyle: {
        color: '#000'
      },
    },
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [120, 200, 150, 80, 70, 110, 130],
        type: 'line'
      }
    ]
  };
  lineChart.setOption(lineOption)
}
onMounted(() => {
  chartfn()
  linefn()
  piefn()
})
</script>


<style lang="less" scoped>
.echarts {
  width: 100vw;
  height: 10vh;
  background-color: #fff;
}

header {
  width: 100%;
  background-color: #005FCD;
  display: flex;
  justify-content: center;
  align-items: center;
}

.body {
  height: 90vh;
  background-color: #f5f5ff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .item {
    padding-top: .625rem;
    width: 30vw;
    height: 80%;
    background-color: #fff;
  }
}

</style>